
<!-- 
@descrition: 直接下推
@auth: xjp 
-->
<template>
	<view class="wc-box">
		<view 
			v-for="(item, index) in list"
			class="wc-box-item" 
			:index="index" 
			:key="index"
			@click="collapseChange(item, index)" 
			>
			<!-- S 标题 -->
			<view class="item-header flex-between">
				<view>
					<text>{{ item.name }}</text>
					<text class="count">({{ item.num }})</text>
				</view>
				<view v-if="item.num > 0">
					<view v-show="collapseActives.includes(index)">
						<u-icon name="arrow-up" color="#666666" size="20"></u-icon>
					</view>
					<view v-show="!collapseActives.includes(index)">
						<u-icon name="arrow-down" color="#666666" size="20"></u-icon>
					</view>
				</view>
			</view>
			<!-- E 标题 -->
			
			<!-- 下级 -->
			<view class="item-body " v-show="collapseActives.includes(index)">
				<view 
					v-for="(uItem, uIndex) in item.child" 
					:key="uIndex"
					class="sub-item flex-between"
				>
					<view class="flex-between">
						<view class="img1" v-if="uItem.avatar">
							<u-image width="80rpx" height="80rpx" :src="uItem.avatar" mode="widthFix"
							 shape="circle"></u-image>
							 
						</view>
						<view class="img2"  v-else>
							<u-image 
								width="40rpx" 
								height="40rpx"  
								src="/static/images/headimgurl.png" 
								mode="widthFix"
								shape="circle">
							</u-image>
						</view>
						<text class="fs28 ppol">{{ uItem.nickname }}</text>
					</view>
					<view class="fs28 color-66"> {{ uItem.create_time }} </view>
					<view class="fs28 color-66"> {{ uItem.mobile.replace(/(\d{3})\d{4}(\d{4})/, '$1****$2') }} </view>
				</view>
				
			</view>
			
		</view>
	</view>
</template>

<script>
	/**
	 * @descrition: '' 
	 * @auth: '' 
	 */
	import request from "@/utils/request";
	
	export default {
		props: {
			// direct=直推;indirect=间推
			type: {
				type: String,
				default: 'direct'
			}
		},
		data() {
			return {
				list: [],
				collapseActives: []
			}
		},
		computed: {},
		watch:{},
		created() {
			this.getTeamCount(this.type)
		},
		mounted() {},
		methods: {
			collapseChange(row, index) { //查看列表
				this.setCollapseActives(index)
				if (row.num) {
					this.getUnderMebmer(row.id, index)
				}
				
			},
			setCollapseActives(index) {
				const ind = this.collapseActives.findIndex(item => item === index)
				if (ind === -1) {
					this.collapseActives.push(index)
				} else {
					this.collapseActives.splice(ind, 1)
				}
			},
			getJsonData() {
				// this.list = res.data.
				this.getTeamCount()
				
			},
			/** 
			 * 进入页面需要请求的数据
			 * @param {Object} type
			 */
			getTeamCount() {
				this.teamList = [];
				const vm = this;
				uni.showLoading({
					title: '加载中'
				});
				request.get("user/getTeamCount", {
					params : {
						type: vm.type
					}
				}).then(res => {
					vm.list = res.map(item => {
						return {
							...item,
							child: []
						}
					})
			    }).finally(() => {
					uni.hideLoading();
				})
			},
			getUnderMebmer(levelId, index) {
				var vm = this;
				uni.showLoading({
					title: '加载中'
				});
				request.get("user/getTeamUserList", {
					params : {
						type: vm.type,
						level_id: levelId
					}
				}).then(res => {
					vm.list[index].child = res
					uni.hideLoading();
				}).finally(() => {
					uni.hideLoading();
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	$font-color-dark: #333333;
	.fs28 {
		font-size: 28rpx;
	}
	.color-66 {
		color: #666666;
	}
	.flex-between {
		display: flex;
		flex-direction: row;
		justify-content: space-between;
		align-items: center;
	}
	.wc-box {
		height: 100%;
		background: #f3f3f3;
		padding: 30rpx;
	}
	.wc-box-item {
		display: block;
		position: relative;
		width: 100%;
		padding: 0 20rpx;
		background-color: #ffffff;
		margin-bottom: 20rpx;
		box-shadow: 0px 10rpx 20rpx 0px rgba(0, 0, 0, 0.04);
		border-radius: 20rpx;
		overflow: hidden;
		
	}
	.item-header {
		display: flex;
		flex-direction: row;
		justify-content: space-between;
		align-items: center;
		height: 100rpx;
		color: $font-color-dark;
		font-size: 28rpx;
		.count {
			color: $font-color-dark;
			font-size: 28rpx;
			margin-left: 5rpx;
		}
	}
	.item-body {
		.sub-item {
			display: flex;
			flex-direction: row;
			justify-content: space-between;
			align-items: center;
			height: 100rpx;
			padding: 0 30rpx;
		}
		.img {
			width: 80rpx;
			height: 80rpx;
		}
		.ppol{
			display: block;
			width: 120rpx;
			white-space: nowrap;
			overflow: hidden;
			text-overflow: ellipsis;
		}
	}
</style>